home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / createSubdPrimitive.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  7.1 KB  |  217 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. // Alias|Wavefront Script File
  19. // MODIFY THIS AT YOUR OWN RISK
  20. //
  21. // Creation Date:  Dec 2000
  22. //
  23. //  Procedure Name:
  24. //      createSubdPrimitive
  25. //
  26. //  Description:
  27. //        Create a subd primitive from a polyPrimitive or a makeNurbPrimitive
  28. //
  29. //  Input Arguments:
  30. //      int $makeType: 1 or 2 (nurbs or poly)
  31. //        string $primitiveType: primitive (Square, Cube, Cone, Plane, Torus, Cylinder)
  32. //
  33. //  Return Value:
  34. //      None.
  35. //
  36.  
  37. proc primitiveWarning(){
  38.     warning "This Subdiv Primitive is made of multiple surfaces. Use Subdiv Surfaces->Attach to make a single surface.";
  39. }
  40.  
  41. proc extraConnectionsForCube(int $makePrimitive, string $primitive, string $makeNode, 
  42.     string $conversionNode){
  43.  
  44.     string $conversion,        //name of created conversion node
  45.         $subdiv,            //name of created subdiv surface    
  46.         $outAttribute,        //out attribute from creation primitive
  47.         $inAttribute,        //in attribute for conversion node
  48.         $toSubd;            //out attribute from conversion node
  49.  
  50.     $inAttribute = ".inputSurface";
  51.     $toSubd = ".outputSubd";
  52.  
  53.     int $extraConnections = 5;
  54.  
  55.     for ($i=1;$i<=$extraConnections;$i++){
  56.         //create nodes and store their names
  57.         $conversion = `createNode $conversionNode -name "toSubdiv#"`;
  58.         $subdiv = `createNode subdiv -name "subdiv#"`;
  59.         $outAttribute = (".outputSurface" + $i);
  60.  
  61.         //connect the nodes
  62.         connectAttr -f ($primitive + $outAttribute) ($conversion + $inAttribute);
  63.         connectAttr -f ($conversion + $toSubd) ($subdiv+".create");
  64.         select -r $subdiv ;
  65.  
  66.         //assign default shader to new subdiv
  67.         sets -e -forceElement initialShadingGroup;
  68.     }
  69.  
  70.     primitiveWarning;
  71. }
  72.  
  73. proc extraConnectionsForRevolve(int $primitiveType, string $primitive, 
  74.     string $conversionNode){
  75.  
  76.     string $conversion,        //name of created conversion node
  77.         $subdiv,            //name of created subdiv surface    
  78.         $outAttribute,        //out attribute from creation primitive
  79.         $inAttribute,        //in attribute for conversion node
  80.         $toSubd,            //out attribute from conversion node
  81.         $cap;                //cap name
  82.  
  83.     int $extraConnections;
  84.  
  85.     $inAttribute = ".inputSurface";
  86.     $outAttribute = ".outputSurface";
  87.     $toSubd = ".outputSubd";
  88.  
  89.     if ($primitiveType == 3) $extraConnections = 2;
  90.     if ($primitiveType == 4) $extraConnections = 1;
  91.  
  92.     for ($i=1;$i<=$extraConnections;$i++){
  93.         //create nodes and store their names
  94.         $conversion = `createNode $conversionNode -name "toSubdiv#"`;
  95.         $subdiv = `createNode subdiv -name "subdiv#"`;
  96.         $cap = `createNode revolve -name "cap#"`;
  97.  
  98.         //connect the nodes
  99.         switch ($i){
  100.             case 1:
  101.                 connectAttr -f ($primitive + ".bottomCapCurve") ($cap + ".inputCurve");
  102.                 break;
  103.             case 2:
  104.                 connectAttr -f ($primitive + ".topCapCurve") ($cap + ".inputCurve");
  105.                 break;
  106.         }
  107.         connectAttr -f ($primitive + ".tolerance") ($cap + ".tolerance");
  108.         connectAttr -f ($primitive + ".sections") ($cap + ".sections");
  109.         connectAttr -f ($primitive + ".axis") ($cap + ".axis");
  110.         connectAttr -f ($primitive + ".degree") ($cap + ".degree");
  111.         connectAttr -f ($primitive + ".useTolerance") ($cap + ".useTolerance");
  112.         connectAttr -f ($primitive + ".absoluteSweepDifference") ($cap + ".endSweep");
  113.         connectAttr -f ($primitive + ".pivot") ($cap + ".pivot");
  114.         //connectAttr -f ($primitive + ".startSweep") ($cap + ".startSweep");
  115.  
  116.         connectAttr -f ($cap + $outAttribute) ($conversion + $inAttribute);
  117.         connectAttr -f ($conversion + $toSubd) ($subdiv+".create");
  118.         select -r $subdiv ;
  119.  
  120.         //assign default shader to new subdiv
  121.         sets -e -forceElement initialShadingGroup;
  122.     }
  123.  
  124.     primitiveWarning;
  125. }
  126.  
  127. global proc createSubdPrimitive(int $makeType, int $primitiveType){
  128.     string $primitive,        //name of created primitive node
  129.         $conversion,        //name of created conversion node
  130.         $subdiv,            //name of created subdiv surface
  131.         $makePrefix,        //prefix for the creation primitive
  132.         $conversionPrefix,    //prefix for the to subd conversion node
  133.         $makeNode,            //creation primitive name
  134.         $conversionNode,    //conversion node name (nurbs or poly to subdiv)
  135.         $outAttribute,        //out attribute from creation primitive
  136.         $inAttribute,        //in attribute for conversion node
  137.         $toSubd,            //out attribute from conversion node
  138.         $makePrimitive;        //primitive type
  139.  
  140.     //determine node and attribute names based on $makeType (nurbs or poly)
  141.     if ($makeType == 1){
  142.         $makePrefix = "makeNurb";
  143.         $conversionPrefix = "nurbs";
  144.         $outAttribute = ".outputSurface";
  145.         $inAttribute = ".inputSurface";
  146.         $toSubd = ".outputSubd";
  147.     }
  148.     else {
  149.         $makePrefix = "poly";
  150.         $conversionPrefix = "poly";
  151.         $outAttribute = ".output";
  152.         $inAttribute = ".inMesh";
  153.         $toSubd = ".outSubdiv";
  154.         
  155.         if ($makeType != 2){
  156.             warning "createSubdPrimitive expected 1 or 2 for first command argument - setting to 2.";
  157.         }
  158.     }
  159.  
  160.     //determine primitive type
  161.     if ($primitiveType > 6 || $primitiveType < 1){
  162.         $primitiveType = 1;
  163.         warning "createSubdPrimitive expected a value between 1 and 6 for second command argument - setting to 1.";
  164.     }
  165.     switch($primitiveType){
  166.         case 1:
  167.             $makePrimitive = "Sphere";
  168.             break;
  169.         case 2:
  170.             $makePrimitive = "Cube";
  171.             break;
  172.         case 3:
  173.             $makePrimitive = "Cylinder";
  174.             break;
  175.         case 4:
  176.             $makePrimitive = "Cone";
  177.             break;
  178.         case 5:
  179.             $makePrimitive = "Plane";
  180.             break;
  181.         case 6:
  182.             $makePrimitive = "Torus";
  183.             break;
  184.     }
  185.  
  186.     //determine node names based on above if/else
  187.     $makeNode = ($makePrefix + $makePrimitive);
  188.     $conversionNode = ($conversionPrefix + "ToSubdiv");
  189.  
  190.     //create nodes and store their names
  191.     $primitive = `createNode $makeNode -name "inputPrimitive#"`;
  192.     $conversion = `createNode $conversionNode -name "toSubdiv#"`;
  193.     $subdiv = `createNode subdiv -name "subdiv#"`;
  194.  
  195.     //connect the nodes
  196.     connectAttr -f ($primitive + $outAttribute) ($conversion + $inAttribute);
  197.     connectAttr -f ($conversion + $toSubd) ($subdiv+".create");
  198.     select -r $subdiv ;
  199.  
  200.     //assign default shader to new subdiv
  201.     sets -e -forceElement initialShadingGroup;
  202.  
  203.     //nurbs cube, cylinder and cone have more than one surface
  204.     //so extra nodes and connections should be made
  205.     if ($makeType == 1){
  206.         if ($primitiveType == 2){
  207.             extraConnectionsForCube $primitiveType $primitive $makeNode $conversionNode;
  208.         }
  209.         else if ($primitiveType == 3 || $primitiveType == 4){
  210.             extraConnectionsForRevolve $primitiveType $primitive $conversionNode;
  211.         }
  212.     }
  213.  
  214.     print ("// Result: Subdiv " + $makePrimitive + " created. //\n");
  215.     
  216. }
  217.